package com.neuedu.service.physician.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neuedu.bean.Register;
import com.neuedu.bean.RestBean;
import com.neuedu.mapper.CheckRequestMapper;
import com.neuedu.mapper.DisposalRequestMapper;
import com.neuedu.mapper.InspectionRequestMapper;
import com.neuedu.mapper.PrescriptionMapper;
import com.neuedu.mapper.RegisterMapper;
import com.neuedu.service.physician.PhysicianPatientService;
@Service
public class PhysicianPatientServiceImpl implements PhysicianPatientService {
	@Autowired
	private RegisterMapper registerMapper;
	@Autowired
	private CheckRequestMapper checkRequestMapper;
	@Autowired
	private InspectionRequestMapper inspectionRequestMapper;
	@Autowired
	private PrescriptionMapper prescriptionMapper;
	@Autowired
	private DisposalRequestMapper disposalRequestMapper;
	@Override
	public Integer getFinishPatientCount(Integer employeeId) {
		// TODO Auto-generated method stub
//		return registerMapper.getPatientByStateCount(employee_id, null,null,"2");
		QueryWrapper<Register> qw=new QueryWrapper<>();		
		qw.eq("employee_id", employeeId)
		.eq("visit_state",2)
		.apply("DATEDIFF(visit_date,CURDATE())=0");
		String val=registerMapper.selectCount(qw).toString();
		System.out.println("val="+val);
		return Integer.valueOf(val);
	}
	@Override
	public Integer getWaitPatientCount(Integer employeeId) {
		// TODO Auto-generated method stub
//		return registerMapper.getWaitPatientCount(employee_id);
		QueryWrapper<Register> qw=new QueryWrapper<>();		
		qw.eq("employee_id", employeeId)
		.eq("visit_state",1)
		.apply("DATEDIFF(visit_date,CURDATE())=0");
		String val=registerMapper.selectCount(qw).toString();
		return Integer.valueOf(val);
	}
	@Override
	public RestBean<List<Register>> getWaitPatient(Integer employeeId, 
			String caseNumber, 
			String realName, 
			Integer nowPageNumber,
			Integer pageSize) {
		// TODO Auto-generated method stub
		System.out.println("employee_id="+employeeId+",nowPageNumber="+nowPageNumber+",pageSize="+pageSize);
		IPage<Register> page = new Page<>(nowPageNumber,pageSize);
		QueryWrapper<Register> qw=new QueryWrapper<>();
//		附加治疗状态
		qw.eq("visit_state", 1);
//		附加日期
		qw.apply("DATEDIFF(visit_date,CURDATE())=0");
//		附加其他条件
		if(employeeId!=null){
			qw.eq("employee_id", employeeId);
		}
		if(caseNumber!=null && caseNumber.length()>0){
			qw.eq("case_number", caseNumber);
		}
		if(realName!=null && realName.length()>0){
			qw.eq("real_name", realName);
		}
		qw.orderByDesc("visit_date");
		IPage<Register> result=registerMapper.selectPage(page,qw);
		List<Register> list=result.getRecords();
		long total=result.getTotal();
		RestBean<List<Register>> rb=new RestBean<>(list,total);
		return rb;
	}
	@Override
	public RestBean getPatientQuery(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public RestBean getPatientItemByItemtype(Integer register_id, String string) {
		// TODO Auto-generated method stub
		return null;
	}
	
}
